package com.gupao.javap6.pattern.proxy;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * TODO
 *
 * @author withinfly(45度C)
 * @date 2020/3/1 23:16
 */
@Data
@Accessors(chain = true)
public class UserServiceImpl implements IBasicMapper<UserEntity> {
    private static final long serialVersionUID = 1L;

    @Override
    public int add(UserEntity object) {
        DB.put(object.getUserId(), object);
        System.out.println("------->>>>> 新增用户：" + JSONObject.toJSONString(object));
        return 1;
    }

    @Override
    public int delete(Serializable id) {
        DB.remove(id);
        System.out.println("------->>>>> 删除用户：" + id);
        return 1;
    }

    @Override
    public int update(UserEntity object) {
        DB.put(object.getUserId(), object);
        System.out.println("------->>>>> 编辑用户：" + JSONObject.toJSONString(object));
        return 1;
    }

    @Override
    public UserEntity select(Serializable id) {
        UserEntity userEntity = DB.get(id);
        System.out.println("------->>>>> 根据ID："+id+" ，查询用户：" + JSONObject.toJSONString(userEntity));
        return userEntity;
    }

    @Override
    public List<UserEntity> selectAll() {
        List<UserEntity> values = DB.values();
        System.out.println("------->>>>> 查询所以用户：" + JSONObject.toJSONString(values));
        return values.stream().collect(Collectors.toList());
    }

}
